# Maintainer: Konstantin Gizdov <arch at kge dot pw>

_pyname=xxhash
pkgname="python-${_pyname}"
pkgver=3.2.0
pkgrel=2
pkgdesc='Python binding for xxHash'
arch=('loong64' 'x86_64')
url="https://github.com/ifduyue/${pkgname}"
depends=('python' 'xxhash')
makedepends=('git' 'python-setuptools-scm' 'python-build' 'python-installer' 'python-wheel')
license=('BSD')
source=("${pkgname}::git+https://github.com/ifduyue/${pkgname}.git#tag=v${pkgver}")
sha512sums=('SKIP')

prepare() {
    # link to xxHash
    export XXHASH_LINK_SO=1
}

build() {
    cd "${srcdir}/${pkgname}"
    python -m build --wheel --no-isolation
}

check() {
    cd "${srcdir}/${pkgname}"
    # name clash is preventing import, rename source temporarily
    # don't forget to rename back after running tests
    mv xxhash _noxxhash
    local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
    PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-${python_version}" python -m unittest discover -vs tests
    mv _noxxhash xxhash
}

package() {
    cd "${srcdir}/${pkgname}"
    python -m installer --destdir="${pkgdir}" dist/*.whl
    install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
